package com.ydm.myapp001.activity;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.ydm.myapp001.R;
import com.ydm.myapp001.receiver.ThirdReceiver;

public class DynamicBCR001Activity extends AppCompatActivity {
    private static final String TAG = "YDMLog_DynamicBCR001";
    private Context mContext;
    private TextView tv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dynamic_bcr001);
        mContext = this;

        /**** 动态注册广播 ****/
        //1.IntentFilter
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("BCR_Third");
        //2.广播接收器
        ThirdReceiver thirdReceiver = new ThirdReceiver();
        //3.注册广播
        registerReceiver(thirdReceiver, intentFilter);
        //
        thirdReceiver.setReceiverListener(new ThirdReceiver.ThirdReceiverCallBack() {
            @Override
            public void receiverBroadcastWithContent(String content) {
                Log.d(TAG, "DynamicBCR001接收到广播内容为："+content);
                tv.setText(content);
            }
        });



        //
        tv = (TextView) findViewById(R.id.tv_bcr_content);
    }

    public void goToBCR002Activity(View v) {
        Intent intent = new Intent(mContext, DynamicBCR002Activity.class);
        startActivity(intent);
    }
}
